package zct.proj.equipModel;

import java.util.HashMap;

import android.graphics.Point;
import zct.proj.pojo.EquipmentInfo;
import zct.proj.util.Const;

public class JYJModel extends BaseModel {

	private HashMap<String, JYJInfo> infoMap = new HashMap<String, JYJInfo>();
	
	public JYJModel(float scale, int cellWidth, int cellHeight) {
		super(scale, cellWidth, cellHeight);
	}
	
	public JYJInfo getJYJInfo(EquipmentInfo detail) {

		String key = detail.getType() + "_" + detail.getDir() + "_" + detail.getWidth() + "_" + detail.getHeight();
		
		JYJInfo jInfo = infoMap.get(key);
		if (jInfo != null) {
			return jInfo;
		}
		
		int disX = (int) (0.3f * xSpacing * detail.getWidth());
		int disY = (int) (0.3f * ySpacing * detail.getHeight());
		// 中心点
		Point pc = new Point((detail.getWidth() + 1) / 2 * xSpacing, (detail.getHeight() + 1) / 2 * ySpacing);
		Point p1 = new Point();
		Point p2 = new Point();
		switch (detail.getDir()) {
		case Const.DIR_NORMAL:
			// -
			p1.set(pc.x - disX, pc.y);
			p2.set(pc.x + disX, pc.y);
			break;
		case Const.DIR_VCOPY:
			// \
			p1.set(pc.x - disX, pc.y - disY);
			p2.set(pc.x + disX, pc.y + disY);
			break;
		case Const.DIR_ROTATE:
			// |
			p1.set(pc.x, pc.y - disY);
			p2.set(pc.x, pc.y + disY);
			break;
		case Const.DIR_HCOPY:
			// /
			p1.set(pc.x - disX, pc.y + disY);
			p2.set(pc.x + disX, pc.y - disY);
			break;
		}
		jInfo = new JYJInfo(p1, p2, pc);
		infoMap.put(key, jInfo);
		return jInfo;
	}
}
